﻿<%@ Page Title="用户管理" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="UserManage.aspx.cs" Inherits="WebForm.UserManage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div class="container mt-4">
        <!-- 添加用户模块 -->
        <div class="card shadow mb-4">
            <div class="card-header bg-success text-white">
                <h4 class="mb-0">添加用户</h4>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <asp:Label ID="lblName" runat="server" Text="姓名" CssClass="form-label"></asp:Label>
                        <asp:TextBox ID="txtAddName" runat="server" CssClass="form-control">
                        </asp:TextBox>
	                    <asp:RequiredFieldValidator ID="rfvAddName" runat="server" 
	                                                ControlToValidate="txtAddName"
	                                                ErrorMessage="姓名不能为空"
	                                                ValidationGroup="AddUserGroup"
	                                                Display="Dynamic"
	                                                ForeColor="Red"
	                                                CssClass="invalid-feedback">
	                    </asp:RequiredFieldValidator>
                    </div>
                    <div class="col-md-4 mb-3">
                        <asp:Label ID="lblEmail" runat="server" Text="邮箱" CssClass="form-label"></asp:Label>
                        <asp:TextBox ID="txtAddEmail" runat="server" CssClass="form-control">
                        </asp:TextBox>
	                    <asp:RequiredFieldValidator ID="rfvAddEmail" runat="server" 
	                                                ControlToValidate="txtAddEmail"
	                                                ErrorMessage="邮箱不能为空"
	                                                ValidationGroup="AddUserGroup"
	                                                Display="Dynamic"
	                                                ForeColor="Red"
	                                                CssClass="invalid-feedback">
	                    </asp:RequiredFieldValidator>
                    </div>
                    <div class="col-md-4 mb-3">
                        <asp:Label ID="lblGender" runat="server" Text="性别" CssClass="form-label"></asp:Label>
                        <asp:DropDownList ID="ddlAddGender" runat="server" CssClass="form-select">
                            <asp:ListItem Value="1">男</asp:ListItem>
                            <asp:ListItem Value="0">女</asp:ListItem>
                        </asp:DropDownList>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <asp:Label ID="lblPassword" runat="server" Text="密码" CssClass="form-label"></asp:Label>
                        <asp:TextBox ID="txtAddPassword" runat="server" TextMode="Password" CssClass="form-control">
	                        
                        </asp:TextBox>
	                    <asp:RequiredFieldValidator ID="rfvAddPassword" runat="server" 
	                                                ControlToValidate="txtAddPassword"
	                                                ErrorMessage="密码不能为空"
	                                                ValidationGroup="AddUserGroup"
	                                                Display="Dynamic"
	                                                ForeColor="Red"
	                                                CssClass="invalid-feedback">
	                    </asp:RequiredFieldValidator>
                    </div>
                    <div class="col-md-4 mb-3">
                        <asp:Label ID="lblPhoneNumber" runat="server" Text="手机号" CssClass="form-label"></asp:Label>
                        <asp:TextBox ID="txtAddPhoneNumber" runat="server" CssClass="form-control">
	                       
                        </asp:TextBox>
	                    <asp:RequiredFieldValidator ID="rfvAddPhoneNumber" runat="server" 
	                                                ControlToValidate="txtAddPhoneNumber"
	                                                ErrorMessage="手机号不能为空"
	                                                ValidationGroup="AddUserGroup"
	                                                Display="Dynamic"
	                                                ForeColor="Red"
	                                                CssClass="invalid-feedback">
	                    </asp:RequiredFieldValidator>
                    </div>
                    <div class="col-md-4 mb-3">
                        <asp:Label ID="lblDateOfBirth" runat="server" Text="出生日期" CssClass="form-label"></asp:Label>
                        <asp:TextBox ID="txtAddDateOfBirth" runat="server" CssClass="form-control" TextMode="Date">
	                        
                        </asp:TextBox>
	                    <asp:RequiredFieldValidator ID="rfvAddDateOfBirth" runat="server" 
	                                                ControlToValidate="txtAddDateOfBirth"
	                                                ErrorMessage="出生日期不能为空"
	                                                ValidationGroup="AddUserGroup"
	                                                Display="Dynamic"
	                                                ForeColor="Red"
	                                                CssClass="invalid-feedback">
	                    </asp:RequiredFieldValidator>
                    </div>
                </div>
                <asp:Button ID="btnAddUser" runat="server" Text="添加用户" CssClass="btn btn-success" ValidationGroup="AddUserGroup" OnClick="btnAddUser_Click" />
            </div>
        </div>
	    <div class="card shadow mb-4">
		    <div class="card-header bg-info text-white">
			    <h4 class="mb-0">搜索用户</h4>
		    </div>
		    <div class="card-body">
			    <div class="col-md-4 mb-3">
				    <asp:Label ID="lblSearchName" runat="server" Text="姓名" CssClass="form-label"></asp:Label>
				    <asp:TextBox ID="txtSearchName" runat="server" CssClass="form-control"></asp:TextBox>
			    </div>
			    <div class="col-md-4 mb-3">
				    <asp:Button ID="btnSearch" runat="server" Text="搜索" CssClass="btn btn-info" OnClick="btnSearch_Click" />
				    <asp:Button ID="btnReset" runat="server" Text="重置" CssClass="btn btn-secondary ms-1" OnClick="btnReset_Click" />
			    </div>
		    </div>
	    </div>
        <!-- 用户管理表格 -->
        <div class="card shadow">
            <div class="card-header bg-primary text-white">
                <h4 class="mb-0">用户管理</h4>
            </div>
            <div class="card-body">
                <asp:GridView ID="GridView1"  EnableSortingAndPagingCallbacks="false"  runat="server"
                    DataKeyNames="ID" 
                    AutoGenerateColumns="false" 
                    AllowPaging="true" PageSize="6"
                    AllowSorting="true"
                    OnRowEditing="GridView1_RowEditing"
                    OnRowUpdating="GridView1_RowUpdating"
                    OnRowCancelingEdit="GridView1_RowCancelingEdit"
                    OnRowDeleting="GridView1_RowDeleting"
                    OnPageIndexChanging="GridView1_PageIndexChanging"
                    OnSorting="GridView1_Sorting" 
                    CssClass="table table-striped table-bordered table-hover"
                    HeaderStyle-CssClass="table-primary"
                    PagerStyle-CssClass="pagination"
                    PagerSettings-Mode="NumericFirstLast"
                    GridLines="None">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" 
                            ItemStyle-CssClass="fw-bold" SortExpression="ID"/>
                        <asp:TemplateField HeaderText="姓名">
                            <ItemTemplate><%# Eval("Name") %></ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtName" runat="server" 
                                    Text='<%# Bind("Name") %>'
                                    CssClass="form-control form-control-sm"/>
	                            <asp:RequiredFieldValidator ID="rfvName" runat="server"
	                                                        ControlToValidate="txtName"
	                                                        ErrorMessage="姓名不能为空"
	                                                        ValidationGroup="EditUserGroup" 
	                                                        Display="Dynamic"
	                                                        ForeColor="Red">
	                            </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="邮箱">
                            <ItemTemplate><%# Eval("Email") %></ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtEmail" runat="server" 
                                    Text='<%# Bind("Email") %>'
                                    CssClass="form-control form-control-sm"/>
	                            <asp:RequiredFieldValidator ID="rfvEmail" runat="server"
	                                                        ControlToValidate="txtEmail"
	                                                        ErrorMessage="邮箱不能为空"
	                                                        ValidationGroup="EditUserGroup" 
	                                                        Display="Dynamic"
	                                                        ForeColor="Red">
	                            </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="性别">
                            <ItemTemplate><%# Eval("Gender").ToString() == "1" ? "男" : "女" %></ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlGenderEdit" runat="server" CssClass="form-select form-select-sm">
                                    <asp:ListItem Value="1">男</asp:ListItem>
                                    <asp:ListItem Value="0">女</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="手机号">
                            <ItemTemplate><%# Eval("PhoneNumber") %></ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtPhoneNumberEdit" runat="server" 
                                    Text='<%# Bind("PhoneNumber") %>'
                                    CssClass="form-control form-control-sm"/>
	                            <asp:RequiredFieldValidator ID="rfvPhoneNumber" runat="server"
	                                                        ControlToValidate="txtPhoneNumberEdit"
	                                                        ErrorMessage="手机号不能为空"
	                                                        ValidationGroup="EditUserGroup" 
	                                                        Display="Dynamic"
	                                                        ForeColor="Red">
	                            </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="出生日期">
                            <ItemTemplate><%# Eval("DateOfBirth", "{0:yyyy/M/d}") %></ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtDateOfBirthEdit" runat="server" 
                                            Text='<%# Bind("DateOfBirth", "{0:yyyy-MM-dd}") %>'
                                    CssClass="form-control form-control-sm"
                                    TextMode="Date"/>
	                            <asp:RequiredFieldValidator ID="rfvDateOfBirth" runat="server"
	                                                        ControlToValidate="txtDateOfBirthEdit"
	                                                        ErrorMessage="出生日期不能为空"
	                                                        ValidationGroup="EditUserGroup" 
	                                                        Display="Dynamic"
	                                                        ForeColor="Red">
	                            </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="操作" ItemStyle-Width="150">
                            <ItemTemplate>
                                <asp:LinkButton runat="server" CommandName="Edit"
                                                CssClass="btn btn-sm btn-primary">
                                    编辑
                                </asp:LinkButton>
                                <asp:LinkButton runat="server" CommandName="Delete" 
                                                CssClass="btn btn-sm btn-danger ms-1"
                                                OnClientClick="return confirm('确认删除吗？');">
                                    删除
                                </asp:LinkButton>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:LinkButton runat="server" CommandName="Update"
                                                ValidationGroup="EditUserGroup"
                                                CssClass="btn btn-sm btn-success">
                                    保存
                                </asp:LinkButton>
                                <asp:LinkButton runat="server" CommandName="Cancel"
                                                CssClass="btn btn-sm btn-secondary ms-1">
                                    取消
                                </asp:LinkButton>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:HyperLinkField 
                            DataNavigateUrlFields="ID" 
                            DataNavigateUrlFormatString="UserDetail.aspx?ID={0}" 
                            DataTextField="Name" 
                            HeaderText="详细信息"/>
                    </Columns>
                    <PagerSettings Position="Bottom"></PagerSettings>
                    <PagerStyle HorizontalAlign="Center" CssClass="pagination"></PagerStyle>
                    <EmptyDataTemplate>
                        <div class="alert alert-info">没有找到用户数据</div>
                    </EmptyDataTemplate>
                </asp:GridView>
            </div>
        </div>
    </div>
</asp:Content>
